use std::{cmp::Ordering, io};

use rand::Rng;

fn main() {
    // 生成随机数字
    println!("生成随机数字");
    let secret_number = rand::thread_rng().gen_range(1..=100);
    print!("随机数是: {secret_number}");
    loop {
        println!("输入您的数字: ");
        let mut guess = String::new();
        io::stdin().read_line(&mut guess).expect("输入错误");
        println!("您输入的是: {guess}");
        let guess: u32 = match guess.trim().parse() {
            Ok(num) => num,
            Err(_) => {
                print!("输入的不是数字哦");
                continue;
            }
        };

        match guess.cmp(&secret_number) {
            Ordering::Less => println!("小了"),
            Ordering::Equal => {
                println!("正确");
                break;
            }
            Ordering::Greater => println!("大了"),
        };
    }
}
